const {body, param} = require('express-validator')
const validate = require('../middleware/validate')
const Banner = require("../models/Banner");

exports.checkBannerId = validate([
  param('id').notEmpty().withMessage('id不能为空')
    .custom(async id => {
      const result = await Banner.findOne({_id: id})
      console.log("-> result", result);
      if (!result) {
        return Promise.reject('传入id错误或者不存在该轮播图')
      }
    }),
])

exports.is_useBanner = validate([
  body('id').notEmpty().withMessage('id不能为空'),
  body('is_use').notEmpty().withMessage('is_use不能为空'),
])
